﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Young3.FMSearch.Core.Entities.GameVersions;
using Young3.FMSearch.Core.Managers;
using Young3.FMSearch.Core.Offsets;
using Young3.FMSearch.Core.Attributes;

namespace Young3.FMSearch.Core.Entities.InGame
{
    //[FMType(UseCache = true)]
    public class Staff : BaseObject
    {
        public Staff(int memoryAddress, IVersion version)
            : base(memoryAddress, version)
        { }
        public Staff(int memoryAddress, ArraySegment<byte> originalBytes, IVersion version)
            : base(memoryAddress, originalBytes, version)
        { }

        public virtual bool isHuman
        {
            get { return false; }
        }

        public Int32 Age { get { return Convert.ToInt32((((TimeSpan)(new Global(Version).IngameDate - DateOfBirth)).TotalDays / 365)); } }

        [FMPointer(StaffOffsets.Nationality)]
        public Country Nationality { get; set; }

        [FMEntityAttribute(StaffOffsets.CityOfBirth)]
        private Int32 CityOfBirthAddress { get; set; }

        [FMEntityAttribute(StaffOffsets.CurrentCoachingAbility)]
        public virtual Int16 CurrentCoachingAbility { get; set; }

        [FMEntityAttribute(StaffOffsets.DateOfBirth)]
        public virtual DateTime DateOfBirth { get; set; }

        [FMEntityAttribute(StaffOffsets.InternationalCaps)]
        public virtual Byte InternationalCaps { get; set; }

        [FMEntityAttribute(StaffOffsets.InternationalGoals)]
        public virtual Byte InternationalGoals { get; set; }

        [FMEntityAttribute(StaffOffsets.Nationality)]
        private Int32 NationalityAddress { get; set; }

        [FMEntityAttribute(StaffOffsets.PotentialCoachingAbility)]
        public virtual Int16 PotentialCoachingAbility { get; set; }

        [FMEntityAttribute(StaffOffsets.U21InternationalCaps)]
        public virtual Byte U21InternationalCaps { get; set; }

        [FMEntityAttribute(StaffOffsets.U21InternationalGoals)]
        public virtual Byte U21InternationalGoals { get; set; }

        [FMEntityAttribute(StaffOffsets.CurrentReputation)]
        public virtual Int16 CurrentReputation { get; set; }

        [FMEntityAttribute(StaffOffsets.HomeReputation)]
        public virtual Int16 HomeReputation { get; set; }

        [FMEntityAttribute(StaffOffsets.WorldReputation)]
        public virtual Int16 WorldReputation { get; set; }

        [FMEntityAttribute(StaffOffsets.Id)]
        public virtual Int32 ID { get; internal set; }

        [FMEntityAttribute(StaffOffsets.FirstName, 0x20)]
        public virtual String FirstName { get; internal set; }

        [FMEntityAttribute(StaffOffsets.LastName, 0x20)]
        public virtual String LastName { get; internal set; }

        [FMEntityAttribute(StaffOffsets.Nickname, 0x20)]
        public virtual String Nickname { get; internal set; }

        [FMPointer(StaffOffsets.CityOfBirth)]
        public virtual City CityOfBirth { get; set; }

        [FMPointer(StaffOffsets.SkillsAdress)]
        public virtual StaffSkills Skills { get; internal set; }

        [FMEntity(StaffOffsets.SkillsAdress)]
        internal Int32 SkillsAddress { get; set; }

        [FMPointer(StaffOffsets.ContractPointer)]
        public virtual Contract Contract { get; internal set; }

        [FMEntity(StaffOffsets.ContractPointer)]
        internal virtual Int32 ContractAddress { get; set; }

        [FMPointer(StaffOffsets.Team)]
        public virtual Team Team { get; internal set; }

        [FMPointer(StaffOffsets.NationalTeam)]
        public virtual Team NationalTeam { get; internal set; }

        public override string ToString()
        {
            return !string.IsNullOrEmpty(Nickname) ? Nickname : FirstName + " " + LastName;
        }

        #region IActiveObject Members

        public int ActiveObjectOffset
        {
            get { return 68; }
        }

        #endregion
    }
}
